package iD220711010131;

/*

dp[i][j]的含义：
将正整数i拆分成j个正整数相加的方法数
  0 1 2 3 4 5 6 7
0 1 0 0 0 0 0 0 0
1 0 1 1 1 1 1 1 1
2 0 0 1 1 2 2 3 3
3 0 0 0 1 1 2 3 4
将正整数i拆分成j个正整数相加的方法数 = 将正整数i-j拆分成j个正整数相加的方法数 + 将正整数i-1拆分成j-1个正整数相加的方法数
比如dp[7][3] = dp[4][3] + dp[6][2];
7 3
1 1 5   1 2 4   1 3 3
2 2 3
4 3
1 1 2
6 2
1 5     2 4     3 3
这是怎么联系起来的呢？


 */

public class MainSubSet3 {
    public static int splitNumber(int N, int K) {
        int[][] dp = new int[N+1][K+1];
        dp[0][0] = 1;
        
        for (int i = 1; i <= N; i++) {
            for (int j = 1; j <= K; j++) {
                if (i >= j) {
                    dp[i][j] = dp[i-j][j] + dp[i-1][j-1];
                }
            }
        }
        
        return dp[N][K];
    }

    public static void main(String[] args) {
        int N = 7;
        int K = 3;
        
        System.out.println("Number of ways to split N into K numbers: " + splitNumber(N, K));
    }
}
